******************************************************************
* Do-file for analysis presented in Shadow of Socialization, v7  *
*                                                                *
*                           March 2017                           *
******************************************************************

use "C:\FDIsurvey.dta", clear

* histogram
twoway (histogram greengoba, color(green)) (histogram magoba, fcolor(none) lcolor(black))

/*tabulate q1a
generate ecosoc_cat=0
replace ecosoc_cat=1 if q1a<1975 & q1a>1959
replace ecosoc_cat=2 if q1a<1960
tabulate ecosoc_cat*/

***************
* MAIN ANALYSIS
***************

oprobit greengoba i.ecosoc_cat i.education i.inchld2 i.skills2 female, vce(robust)
oprobit greengoba i.ecosoc_cat i.education i.inchld2 i.skills2 mncempfam i.partylr brexit local nationalism female, vce(robust)
oprobit magoba i.ecosoc_cat i.education i.inchld2 i.skills2 female, vce(robust)
margins, dydx(*)
oprobit magoba i.ecosoc_cat i.education i.inchld2 i.skills2 mncempfam i.partylr brexit local nationalism female, vce(robust)
margins, dydx(*)

******************
* CAUSAL MEDIATION
******************

* A: without most obviously endogenous controls

* Barry and Kennon method
regress ecostatism i.ecosoc_cat i.education i.inchld2 i.skills2 female, vce(robust)
oprobit magoba ecostatism i.ecosoc_cat i.education i.inchld2 i.skills2 female, vce(robust)

* Imai et al. method
medeff (regress ecostatism old education inchld2 skills2 female) (regress magoba ecostatism old education inchld2 skills2 female), mediate(ecostatism) treat(old) vce(robust)

* B: with endogenous controls

* Barry and Kennon method
regress ecostatism i.ecosoc_cat i.education i.inchld2 i.skills2 mncempfam i.partylr brexit local nationalism female, vce(robust)
oprobit magoba ecostatism i.ecosoc_cat i.education i.inchld2 i.skills2 mncempfam i.partylr brexit local nationalism female, vce(robust)

* Imai et al. method
medeff (regress ecostatism old education inchld2 skills2 mncempfam partylr brexit local nationalism female) (regress magoba old ecostatism education inchld2 skills mncempfam partylr brexit local nationalism female), mediate(ecostatism) treat(old) vce(robust)


***********
* APPENDIX
***********

* DESCRIPTIVES

correlate greengoba magoba ecosoc_cat education inchld2 skills2 mncempfam partylr brexit local nationalism female ecostatism

tabulate greengoba
tabulate magoba 
tabulate old
tabulate education 
tabulate inchld2 
tabulate skills2 
tabulate mncempfam 
tabulate partylr 
tabulate brexit 
tabulate local 
sum nationalism, detail
tabulate female
sum ecostatism, detail
